package com.lanou.wuyou.one;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by dllo on 17/3/9.
 */

public class MainAdapter extends FragmentPagerAdapter{
    private List<Fragment> fragments;
    private String[] titles = new String[]{"拨号盘","通话记录","联系人","短信"};
    private int[] images = new int[]{
            R.drawable.call,
            R.drawable.records,
            R.drawable.contacts,
            R.drawable.note,
    };

    public MainAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return super.getPageTitle(position);
    }
    public View getTabView(int index, Context context){
        View tabView = LayoutInflater.from(context).inflate(R.layout.tab_main_view,null);
        TextView title = (TextView) tabView.findViewById(R.id.main_tv);
        title.setText(titles[index]);
        ImageView imageView = (ImageView) tabView.findViewById(R.id.main_iv);
        imageView.setImageResource(images[index]);
        return tabView;
    }
}
